import { defHttp } from '@/utils/http/axios'
import { ILoginData, ILoginRut, IUserInfoResponse } from './types'

enum API {
  AUTH_CAPTCHA = '/auth/captcha',
  LOGIN = '/auth/login',
  GET_PUBLICK_KEY = '/auth/publicKey',
  USER_INFO = '/user/info'
}

const DEFAULT_OPTS = {
  isTransformResponse: false
}

/** 登录验证码 */
export function getAuthCaptcha() {
  return defHttp.get({
    url: API.AUTH_CAPTCHA
  }, DEFAULT_OPTS)
}

/** 登录 */
export function login(data: ILoginData): Promise<ILoginRut> {
  return defHttp.post({
    url: API.LOGIN,
    data
  }, DEFAULT_OPTS)
}

/** 获取公钥 */
export function getLoginPublicKey() {
  return defHttp.get<string>({
    url: API.GET_PUBLICK_KEY
  }, DEFAULT_OPTS)
}

/** 获取用户信息 */
export function getUserInfo() {
  return defHttp.get<IUserInfoResponse>({
    url: API.USER_INFO
  }, DEFAULT_OPTS)
}
